//
//  ComplainService.m
//  HZHome
//
//  Created by Alawn on 13-10-18.
//  Copyright (c) 2013年 xzysun. All rights reserved.
//

#import "ComplainService.h"
#import "ComplainEntity.h"
#import "ComplainCell.h"
#import "UserInfoService.h"
@implementation ComplainService
-(id)init
{
    self = [super init];
    if (self) {
        _dataItemName = @"ComplainEntity";
    }
    return self;
}
-(void)loadDataWithKey:(NSString *)keyOrNil
{
    _currentPageNo = 1;//刷新或查询的时候将请求页码变为1
    if (self.dataList) {
        self.dataList = nil;
    }
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    UserInfoService *userInfo=[UserInfoService getUserInfoService];
    [params setValue:userInfo.currentLoginUserName forKey:@"userName"];//用户名
    NSString *complainType=[DataStoreService loadFromKeychain:COMPLAINTYPE];
    if (complainType!=nil) {
        [params setValue:complainType forKey:@"type"];//类型
    }
    else{
         [params setValue:@"0,1,2" forKey:@"type"];//类型
    }
    
    if (keyOrNil) {
        [params setValue:keyOrNil forKey:@"dealCode"];
    } else {
        [params setValue:@"" forKey:@"dealCode"];
    }
    [params setValue:getDeviceIdentifier() forKey:@"imsi_code"];//要加入的唯一标示
    [self doHttpPost:JuBaoJiLu headers:nil path:[NSString stringWithFormat:@"/%d",_currentPageNo] parameters:params];    
}

-(void)loadMoreDataWithKey:(NSString *)keyOrNil
{
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    UserInfoService *userInfo=[[UserInfoService alloc]init];
    [params setValue:userInfo.currentLoginUserName forKey:@"userName"];//用户名
    NSString *complainType=[DataStoreService loadFromKeychain:COMPLAINTYPE];
    if (complainType!=nil) {
        [params setValue:complainType forKey:@"type"];//类型
    }
    else{
        [params setValue:@"0,1,2" forKey:@"type"];//类型
    }
    
    if (keyOrNil) {
        [params setValue:keyOrNil forKey:@"dealCode"];
    } else {
        [params setValue:@"" forKey:@"dealCode"];
    }
    [params setValue:getDeviceIdentifier() forKey:@"imsi_code"];//要加入的唯一标示
    [self doHttpPost:JuBaoJiLu headers:nil path:[NSString stringWithFormat:@"/%d",_currentPageNo] parameters:params];
}

-(void)configCell:(UITableViewCell *)cell atIndex:(NSIndexPath *)index
{
    ComplainEntity *item = [self.dataList objectAtIndex:index.row];
    ComplainCell *tempCell = (ComplainCell *)cell;
    tempCell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
//    tempCell.titleLabel.text = item.title;
    tempCell.titleLabel.text = item.dealCode;
    NSString *tempDealStatus=@"未处理";
    if ([item.dealStatus compare:@"0"]==NSOrderedSame) {
        tempDealStatus=@"未处理";
    }
    if ([item.dealStatus compare:@"1"]==NSOrderedSame) {
        tempDealStatus=@"处理中";
    }
    if ([item.dealStatus compare:@"2"]==NSOrderedSame) {
        tempDealStatus=@"已办结";
    }
    tempCell.status.text=tempDealStatus;
}

-(NSDictionary *)getTargetConfigForCellAtIndex:(NSIndexPath *)indexPath
{
    ComplainEntity *item = [self.dataList objectAtIndex:indexPath.row];
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:@"举报记录详情",@"key",item,@"dataItem", nil];
    return dic;
}

-(NSString *)getButtomTips
{
    return @"如果您爱个人电脑上提交的记录没有在此显示，请输入当时的受理编号查询";
}
@end

